
import { Common } from '@/utils/common.js'
import { EmployeesApi } from '@/api/Employees.api'
import { SysWelfarePercentEmployeeConfigApi } from '@/api/SysWelfarePercentEmployeeConfig.api'
import moment from 'moment'

export class EBbase {
  // 查看详情时，解析社保参数配置信息并展示
  static parseConfigInfoIsOnlyView (configInfo, formFilter, tableData) {
    formFilter.rangeGUID = configInfo.rangeGUID, // 社保编号
    formFilter.securityGUID = configInfo.securityGUID // 社保方案

    EBbase.readAddModelValToTable(configInfo.details, tableData, 'baseAmount')
    EBbase.readAddModelValToTable(configInfo.details, tableData, 'percent')
  }

  // 输入补缴月数计算参保时间
  static toCountDate (form, month) {
    form.insuredTime = moment().subtract(month, 'months').format('YYYY-MM-01')
    console.log('form.insuredTime: 🧞‍ ', form.insuredTime)
  }

  // 输入参保时间计算补缴月数
  static toCountMonth (form, date) {
    var month = moment(new Date()).diff(moment(new Date(date)), 'months')
    form.payMonth = month
    console.log('form.payMonth: 🧞‍ ', form.payMonth)
  }

  // 循环社保值到表格
  static readAddModelValToTable (arr, tableData, showType) {
    var baseAmountObj = {}
    arr.map((item) => {
      var companyStr = item.securityTypeCode + 'Company'
      var employeeStr = item.securityTypeCode + 'Employee'
      baseAmountObj = { ...baseAmountObj,
        ...{
          [companyStr]: item.company ? item.company[showType] : '',
          [employeeStr]: item.employee ? item.employee[showType] : ''
        } }
    })
    tableData.push(baseAmountObj)
    console.log('tableData: ', tableData)
    tableData.splice(2, 2)
  }

  // 返回员工花名册列表
  static goEmployeeBookList (router, companyId, companyName) {
    router.push({
      path: '/EmployeeBook',
      name: 'EmployeeBook',
      query: {
        companyId: companyId,
        companyName: companyName
      }
    })
  }

  // 返回员工管理
  static goRoster (router) {
    router.push({
      path: '/roster',
      name: 'roster'
    })
  }
}
